<?php
header( 'Content-Type: text/html; charset=utf-8' );

if (isset($_POST['submit']))
{
	$fehler = false;
	$fehlermeldung = "";
	
	if (empty($_POST['domain']))
	{
		$fehler = true;
		$fehlermeldung .= "Sie müssen eine Domain angeben! <br />";
	}
	if (!isset($_POST['anonymous']))
	{
		if (empty($_POST['username']))
		{
			$fehler = true;
			$fehlermeldung .= "Sie müssen einen Benutzernamen angeben! <br />";
		}
		if (empty($_POST['password']))
		{
			$fehler = true;
			$fehlermeldung .= "Sie müssen ein Passwort angeben! <br />";
		}
	}
	else
	{
		$_POST['username'] = "anonymous";
	}
	
	if (!empty($fehlermeldung))
	{
		$fehlermeldung = "<div style='margin-bottom:10px; color:red; font-size:12px'>{$fehlermeldung}</div>";
	}
	
	if ($fehler == false)
	{
		session_start();
		$_SESSION['logged_in'] = true;
		$_SESSION['domain'] = $_POST['domain'];
		$_SESSION['port'] = $_POST['port'];
		$_SESSION['username'] = $_POST['username'];
		$_SESSION['password'] = $_POST['password'];
		header('Location: index.php');
	}
}
?>

<html>
	<head>
		<title>Web-FTP Login</title>
		<style type="text/css">
			* {
				font-family: Tahoma, Verdana, Arial;
				font-size: 14px;
			}
			body {
				background: #255c9f url(images/background.png) repeat-x;
			}
			#login-box {
				width: 300px;
				background: #f4f4f4;
				padding: 10px 15px 5px 15px;
				margin-top: 150px;
				-moz-box-shadow: 0 0 10px #000;
				-moz-border-radius: 10px;
				-webkit-box-shadow: 0 0 10px #000;
				-webkit-border-radius: 10px;
				box-shadow: 0 0 10px #000;
				border-radius: 10px;
			}
			form {
				text-align: left;
			}
			#login-form {
				margin: 20px 5px 5px 20px;
			}
			#login-form input {
				height: 25px;
				margin: 4px 0;
				border: 1px solid #8a8a8a;
				padding: 3px 3px 3px 5px;
				cursor: pointer;
				-moz-border-radius: 5px;
				-webkit-border-radius: 5px;
				border-radius: 5px;
			}
			#login-form input:hover {
				border: 1px solid #4a99e3;
			}
			#login-form input:focus {
				background: #e5f2ff;
				border: 1px solid #4a99e3;
				-moz-box-shadow: inset 0 0 3px #c3c3c3;
				-webkit-box-shadow: inset 0 0 3px #c3c3c3;
				box-shadow: inset 0 0 3px #c3c3c3;
			}
			#login-form input.normal {
				width: 185px;
			}
			#login-form input[type=submit]:focus {
				-moz-box-shadow: inset 0 0 3px #9d9d9d;
				-webkit-box-shadow: inset 0 0 3px #9d9d9d;
				box-shadow: inset 0 0 3px #9d9d9d;
			}
		</style>
	</head>
	
	<body>
		<center>
			<div id="login-box">
				<form method="post" action="login.php">
					<fieldset>
						<legend>Web-FTP Login</legend>
						
						<div id="login-form">
							<?php
								if (isset($fehler) && $fehler == true)
									echo $fehlermeldung;
							?>
							<label>(FTP-)Domain:</label><br />
							<input type="text" class="normal" name="domain" size="25" />
							<input type="text" name="port" size="1" style="color: #999" value="21" onfocus="this.value='';this.style.color='#000'" onblur="if(this.value == ''){this.value='21';this.style.color='#999'}" /><br />
							<label>Username:</label><br />
							<input type="text" class="normal" name="username" size="25" /><br />
							<label>Passwort:</label><br />
							<input type="password" class="normal" name="password" size="25" />
							<table>
								<tr>
									<td>
										<input type="checkbox" name="anonymous" />
									</td>
									<td>
        								<label>Anonym anmelden</label>
        							</td>
        						</tr>
							</table>
							<div style="clear: both"></div>
							<input type="submit" name="submit" value="Einloggen" />
						</div>
					</fieldset>
				</form>
			</div>
		</center>
	</body>
</html>